import rtconfig
from building import *

# get current directory
cwd = GetCurrentDir()

# The set of source files associated with this SConscript file.

src = Glob('GD32F4xx_standard_peripheral/Source/*.c')
src += [cwd + '/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c']

#add for startup script
if rtconfig.PLATFORM in ['gcc']:
    src += [cwd + '/CMSIS/GD/GD32F4xx/Source/GCC/startup_gd32f4xx.S']
elif rtconfig.PLATFORM in ['armcc', 'armclang']:
    src += [cwd + '/CMSIS/GD/GD32F4xx/Source/ARM/startup_gd32f450_470.s']
elif rtconfig.PLATFORM in ['iccarm']:
    src += [cwd + '/CMSIS/GD/GD32F4xx/Source/IAR/startup_gd32f450_470.s']

path = [
    cwd + '/CMSIS/GD/GD32F4xx/Include',
    cwd + '/CMSIS',
    cwd + '/GD32F4xx_standard_peripheral/Include',]

if GetDepend('BSP_USING_USBD') or GetDepend('BSP_USING_USBH'):
    path += [cwd + '/GD32F4xx_usb_library/driver/Include', cwd + '/GD32F4xx_usb_library/ustd/common']
    src  += [cwd + '/GD32F4xx_usb_library/driver/Source/drv_usb_core.c']
    if GetDepend('BSP_USING_USBD'):
        src += [cwd + '/GD32F4xx_usb_library/driver/Source/drv_usb_dev.c', cwd + '/GD32F4xx_usb_library/driver/Source/drv_usbd_int.c']
    if GetDepend('BSP_USING_USBH'):
        src += [cwd + '/GD32F4xx_usb_library/driver/Source/drv_usb_host.c', cwd + '/GD32F4xx_usb_library/driver/Source/drv_usbh_int.c']

CPPDEFINES = ['USE_STDPERIPH_DRIVER', 'USE_USB_FS']

group = DefineGroup('Libraries', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')
